package com.guosheng.nettytest;


import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TimeClient {


    public static void getTime(){
        int port = 8080;
        Socket socket = null;
        BufferedReader in = null;
        PrintWriter out = null;

        try {
            socket = new Socket("127.0.0.1",port);
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out = new PrintWriter(socket.getOutputStream(),true);
            out.println("Query time order");
            System.out.println("send order 2 server succeed");
            String resp = in.readLine();
            System.out.println("Now is :" + resp);
        }catch (Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(out != null) out.close();
                if(in != null) in.close();
                if(socket != null) socket.close();
                out = null;
                in = null;
                socket = null;
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args){

        for(int i=0;i<= 100;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    TimeClient.getTime();
                }
            }).start();
        }
    }
}
